package cn.iocoder.yudao.module.ai.utils.sm.sm2;


import cn.iocoder.yudao.module.ai.utils.sm.Util;

/**
 * @author AAA
 * @date 2022/2/9 18:58
 */
public class SM2Util {
    public static final String USER_ID = "1";

    public SM2Util() {
    }

    public static final String encryptBySM2(String plainText, String pubKey) {
        String encrypt = SM2EncDecUtils.encrypt(Util.hexStringToBytes(pubKey), Util.getUTF8Bytes(plainText));
        return encrypt;
    }

    public static final String decryptBySM2(String cipherText, String priKey) {
        byte[] decrypt = SM2EncDecUtils.decrypt(Util.hexStringToBytes(priKey), Util.hexStringToBytes(cipherText));
        return Util.getUTF8String(decrypt);
    }

    public static final String[] generateKeyPairs() {
        SM2KeyVO sm2KeyVO = SM2EncDecUtils.generateKeyPair();
        return new String[]{sm2KeyVO.getPriHexInSoft(), sm2KeyVO.getPubHexInSoft()};
    }

    public static void main(String[] args) {
        //生成公私钥
        String[] strings = generateKeyPairs();
        for (String string : strings) {
            System.out.println(string);
        }
    }
}
